const prefix = 'BLOCK_JOKER'
const db = {
  save(key, value) {
    key = `${prefix}_${key}`
    localStorage.setItem(key, JSON.stringify(value))
  },
  get(key, defaultValue = null) {
    key = `${prefix}_${key}`
    try {
      const value = localStorage.getItem(key)
      if (!value) {
        return value
      }
      return JSON.parse(value) || defaultValue
    } catch (error) {
      console.log(error)
    }
  },
  remove(key) {
    key = `${prefix}_${key}`
    localStorage.removeItem(key)
  },
  clear() {
    localStorage.clear()
  }
}

export default db
